<template>
    <view>
        <button @click="login">登录</button>
        <textarea :value="code"></textarea>
        <button open-type="getUserInfo" @getuserinfo="getUserInfo">授权登录</button>

        <button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">手机登录</button>
    </view>
</template>

<script>
export default {
    data() {
        return {
            code: ''
        };
    },
    methods: {
        getUserInfo(e) {
            let res = e.detail;
            console.log(res);
            let param = {
                code: this.code,
                iv: res.iv,
                signature: res.signature,
                encryptedData: res.encryptedData,
                rawData: res.rawData
            }
            this.apiGetUserInfo(param)
        },
        getPhoneNumber(e) {
            let res = e.detail
            console.log(res);
            let param = {
                code: this.code,
                iv: res.iv,
                encryptedData: res.encryptedData,
            }
            this.apiGetPhone(param)
        },
        login() {
            let that = this;
            wx.login({
                success(res) {
                    console.log(res);
                    that.code = res.code;
                }
            });
        },
        async apiGetUserInfo(param) {
            let res = await this.$request.post({
                url: 'http://127.0.0.1:8080/wechat/getUserInfo',
                skipInterceptorResponse: true,
                business: undefined,
                data: param
            })
            console.log(res)
        },
        async apiGetPhone(param) {
            let res = await this.$request.post({
                url: 'http://127.0.0.1:8080/wechat/getPhone',
                skipInterceptorResponse: true,
                business: undefined,
                data: param
            })
            console.log(res)
        }
    }
};
</script>

<style></style>
